<?php

namespace app\common\arvato;

use app\common\common\Constants;
//use think\cache;    
use think\Cache;

/**
 * Description of Member
 *
 * @author Tommy
 */
class CommonPush extends Base {

    private $_func;
    private $_key;

    /**
     * 插入队列
     * @param type $data
     * @param type $funcName
     * @param type $redisKey
     * @param type $type
     * @return boolean
     */
    public function pushToRedis($data, $funcName = '', $redisKey = '', $type = 'rpush') {
        //从静态变量内获取名称
        if (empty(Constants::$pushArvartoFunc[$funcName])) {
            return false;
        }
        $this->_func = Constants::$pushArvartoFunc[$funcName];
        $this->_key = true === empty($redisKey) ? Constants::$pushArvartoKey['dataArvato'] : $redisKey;
        if ('rpush' == $type) {
            return $this->rpushToRedis($data);
        }
        return false;
    }

    /**
     * RPUSH的方式插入队列
     * @param type $data array(需要插入缓存的数组)
     * @param type $func str (字符串格式的方法)
     * @param type $key (redis的key)
     * @return bool
     */
    protected function rpushToRedis($data) {
        if (empty($data)) {
            return false;
        }
        $params = ['function' => $this->_func, 'data' => $data];
        $value = $this->assemble($params); //组装数据
//        cache::rpush($this->_key, $value);
        Cache::rpush($this->_key, $value);
        return true;
    }

}
